#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'teffy'

'''
@@created on 17-11-7
@poject:python-shoot-game
@author:teffy
'''

import os,sys,pygame
from settings import Settings
from ship import Ship
import game_controller as gc
from pygame.sprite import Group
from enemy import Enemy
from game_stats import GameStats
from button import Button
from scoreboard import Scoreboard

def init_game():
    settings = Settings()
    pygame.init()
    pygame.mixer.init()

    boomsound = pygame.mixer.Sound('./sounds/boom.wav') # 不支持mp3

    screen = pygame.display.set_mode((settings.screen_width,settings.screen_height))
    pygame.display.set_caption('Shoot')

    play_button = Button(settings,screen,'Play')
    stats = GameStats(settings)
    sb = Scoreboard(settings,screen,stats)
    ship = Ship(screen,settings)
    bullets = Group()
    enemys = Group()
    gc.create_enemy(settings,screen,ship,enemys)

    while True:
        gc.check_event(settings,screen,ship,bullets,enemys,stats,play_button,sb)
        if stats.game_active:
            ship.update()
            gc.update_bullets(screen,settings,ship,bullets,enemys,stats,sb,boomsound)
            gc.update_enemy(screen,settings,ship,bullets,enemys,stats,sb)
        gc.update_screen(screen,settings,ship,bullets,enemys,stats,play_button,sb)

if __name__ == '__main__':
    init_game()